package tij4.concurrent.exercise.ex18;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

class Ex18NoRunnable {

    public void fun01() {
        try {
            TimeUnit.SECONDS.sleep(10000000);
        } catch (InterruptedException e) {
            System.out.println("InterruptedException");
        }finally {
            System.out.println("Good Bye");
        }
    }

}

public class Ex18 implements Runnable{

    @Override
    public void run() {
        Ex18NoRunnable ex18NoRunnable = new Ex18NoRunnable();
        ex18NoRunnable.fun01();
    }

    public static void main(String[] args) {
//        ExecutorService executorService = Executors.newCachedThreadPool();
//        Future<?> f = executorService.submit(new Ex18());
//        try{
//            TimeUnit.MILLISECONDS.sleep(100);
//        }catch (InterruptedException e){
//            System.out.println("Sleep interrupted in mian()");
//        }
//        Thread.yield();
//        f.cancel(true);
//        executorService.shutdown();


//        Thread thread = new Thread(new Ex18());
//        thread.start();
//        thread.interrupt();

        ExecutorService executorService = Executors.newSingleThreadExecutor();
        executorService.execute(new Ex18());
        executorService.shutdownNow();

    }
}
